package com.rsscollector.model.vo;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashSet;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "CATEGORY")
public class Category implements Serializable {
    private Long id;
    private String name;
    private String title;
    private boolean active;
    private long sequence;
    private Collection<Category> subCategories = new HashSet<Category>();
    private Category parentCategory;
    private Collection<RssSource> rssSources = new HashSet<RssSource>();

    // No-arg constructor
    public Category() { /* empty */ }

    public Category(String name, boolean active, long sequence, Category parentCategory) {
        this.name = name;
        this.active = active;
        this.sequence = sequence;
        this.parentCategory = parentCategory;
    }
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "CATEGORY_ID")
    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name = "NAME", nullable = false, length = 30)
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "TITLE", nullable = true, length = 100)
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Column(name = "ACTIVE_FLAG", nullable = false)
    public boolean isActive() {
        return this.active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    @Column(name = "SEQUENCE_NUM", nullable = false)
    public long getSequence() {
        return this.sequence;
    }

    public void setSequence(long sequence) {
        this.sequence = sequence;
    }

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "parentCategory")
    public Collection<Category> getSubCategories() {
        return this.subCategories;
    }

    public void setSubCategories(Collection<Category> subCategories) {
        this.subCategories = subCategories;
    }

    @ManyToOne()
    @JoinColumn(name = "PARENT_CATEGORY_ID", nullable = true)
    public Category getParentCategory() {
        return this.parentCategory;
    }

    public void setParentCategory(Category parentCategory) {
        this.parentCategory = parentCategory;
    }

    @ManyToMany()
    public Collection<RssSource> getRssSources() {
        return this.rssSources;
    }

    public void setRssSources(Collection<RssSource> rssSources) {
        this.rssSources = rssSources;
    }
}
